//
//  MBTableViewModel.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/4/18.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBBaseTableViewModel.h"

@interface MBBaseTableViewModel ()
@property (nonatomic,strong) NSMutableArray *dataArray;

@end

@implementation MBBaseTableViewModel

- (UITableViewStyle)tableViewStyle
{
    return UITableViewStyleGrouped;
}

- (UITableViewCellSelectionStyle)tableViewCellSelectionStyle
{
    return UITableViewCellSelectionStyleNone;
}

- (void)factoryInitDataModelArray:(NSArray *)dataArray cellViewModelClass:(Class)cellViewModelClass
{
    NSMutableArray *cellViewModes = [NSMutableArray array];
    [dataArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [cellViewModes addObject:[[cellViewModelClass alloc] initWithDataModel:obj]];
    }];
    [self.dataArray addObjectsFromArray:cellViewModes];
}

#pragma mark - tableView的代理方法实现
// 默认是一个section
- (NSInteger)numberOfSections
{
    return 1;
}

/**
 子类必须实现（每个section多少rows）
 */
- (NSInteger)numberOfRowInSection:(NSInteger)section
{
    @throw [NSException exceptionWithName:@"抽象方法未实现"
                                   reason:[NSString stringWithFormat:@"%@ 必须实现抽象方法 %@",[self class],NSStringFromSelector(_cmd)]
                                 userInfo:nil];
}

/**
 headerView的默认是没有的
 */
- (CGFloat)heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

- (UIView *)viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

-(CGFloat)heightForFooterInSection:(NSInteger)section
{
    return 0;
}

-(UIView *)viewForFooterInSection:(NSInteger)section
{
    return nil;
}


/**
 子类必须实现（返回数据请求回来之后放在cellViewModels数组里面的每个cell对应的cellViewModel）
 */
- (MBBaseTableCellViewModel *)cellViewModelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    @throw [NSException exceptionWithName:@"抽象方法未实现"
                                   reason:[NSString stringWithFormat:@"%@ 必须实现抽象方法 %@",[self class],NSStringFromSelector(_cmd)]
                                 userInfo:nil];
}

-(NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

@end
